package gms.service.match;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import gms.dao.match.MatchInfoDao;
import gms.entities.match.MatchInfo;
import gms.util.PageBean;


@Transactional
public class MatchInfoServiceImp implements MatchInfoService{
	
	private MatchInfoDao matchInfoDao;

	public void setMatchInfoDao(MatchInfoDao matchInfoDao) {
		this.matchInfoDao = matchInfoDao;
	}

	@Override
	public void queryByTime(MatchInfo matchInfo) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void queryByAttr(MatchInfo matchInfo) {
		matchInfoDao.queryByAttr(matchInfo);
		
	}

	/**
	 * 分页查找所有的赛事信息表服务
	 */
	@Override
	public PageBean<MatchInfo> findByPage(int currPage) {
		PageBean<MatchInfo> pageBean = new PageBean<MatchInfo>();
		//封装当前页数
		pageBean.setCurrPage(currPage);
		//每页显示的记录数
		int pageSize = 3;
		pageBean.setPageSize(pageSize);
		//封装总记录数
		int totalCount = matchInfoDao.findCount(); 
		pageBean.setTotalCount(totalCount);
		//封装总页数
		double tc = totalCount;
		Double num = Math.ceil(tc / pageSize); 
		pageBean.setTotalPage(num.intValue());
		//封装每页显示的数据
		int begin = (currPage - 1) * pageSize;
		List<MatchInfo> list = matchInfoDao.findByPage(begin,pageSize);
		pageBean.setList(list);
		return pageBean;
	}

	/**
	 * 通过ID查找赛事信息表服务
	 */
	@Override
	public MatchInfo findByID(int matchInfoID) {
		return matchInfoDao.findByID(matchInfoID);
	}

	/**
	 * 赛事信息表更新服务
	 */
	@Override
	public void update(MatchInfo matchInfo) {
		matchInfoDao.update(matchInfo);
	}

	/**
	 * 赛事信息表删除服务
	 */
	@Override
	public void delete(MatchInfo matchInfo) {
		matchInfoDao.delete(matchInfo);
	}


}
